package Code.Basic.Structures;

import org.jrabbit.standard.game.graphics.skins.image.ImageSkin;
import org.lwjgl.opengl.GL11;

import Code.Basic.Entity.PhysicsSprite;

public class Wall extends PhysicsSprite
{
	private float w;
	private float h;
	
	public Wall(String filepath, float length)
	{
		this(filepath, length, 1);
	}
	
	public Wall(String filepath, float length, float height)
	{
		super(filepath);
		w = length;
		h = height;
		setToRectangle(length * (float) getWidth(), height * (float) getHeight());
		getBody().setMoveable(false);
		getBody().setRotatable(false);
	}
	
	public double getScaledWidth()
	{
		return super.getScaledWidth() * w;
	}
	
	public double getScaledHeight()
	{
		return super.getScaledHeight() * h;
	}
	
	public void draw()
	{
		if(animation.getSkin() instanceof ImageSkin)
		{
			((ImageSkin)animation.getSkin()).object().bind();
		}
		else
		{
			GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
		}
		
		GL11.glBegin(GL11.GL_QUADS);			
		
			float width = (float) (getScaledWidth() / 2);
			float height = (float) (getScaledHeight() / 2);
			
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2f(-width, -height);
			
			GL11.glTexCoord2f(w, 0);
			GL11.glVertex2f(width, -height);
			
			GL11.glTexCoord2f(w, h);
			GL11.glVertex2f(width, height);
			
			GL11.glTexCoord2f(0, h);
			GL11.glVertex2f(-width, height);
		
		GL11.glEnd();
	}
	
}
